; Music of One Man & His Droid (1985) (Mastertronic) (Clive Brooker & Ed Hickman)
; Ripped by Megachur the 22/10/2006
; it's possible now to reallocate it

	write "ONEMA&HD.BIN"

music_date_rip	equ &18a6
music_adr	equ &3d37
first_theme	equ 0
last_theme	equ 0

	read "music_header_v1_0.asm"

;3d37
;
.init_music	;l3d3
;
	call l3d5f
	call l3d72
	ret
;
.send_data_to_ay	;l3d3e modified by Megachur
;
;	push af
;	push bc

;	ld b,#f4
;	out (c),a
;	ld a,#c0
;	ld b,#f6
;	out (c),a
;	xor a
;	out (c),a
;	pop bc
;	push bc
;	ld b,#f4
;	out (c),c
;	ld a,#80
;	ld b,#f6
;	out (c),a
;	xor a
;	out (c),a

;	pop bc
;	pop af
	di		; disable interrupt
	push af
	push bc

	ld b,#f4	; PPI Port A Data
	out (c),a	; Send register number to PPI Port A Data

	ld b,#f6	; PPI Port C
	in a,(c)	; read PPI Port C value
	or #c0		; &11000000 - set PSG fonction selection value to "Select PSG register"
	out (c),a	; send value to PPI Port C
	and #3f		; &00111111 - set PSG fonction selection value to "Inactive"
	out (c),a	; send value to PPI Port C

	ld b,#f4	; PPI Port A Data
	out (c),c	; send data to PPI Port A 

	ld b,#f6	; PPI Port C
	ld c,a		; c = "Inactive" = a
	or #80		; &10000000 - set PSG fonction selection value to "Write to selected PSG register"
	out (c),a	; send value to PPI Port C
	out (c),c	; send "Inactive" to PPI Port C

	pop bc
	pop af
	ei		; enable interrupt
	ret
;
.stop_music
.l3d5f
;
	ld b,#0e
.l3d61
	ld a,b
	dec a
	ld c,#00
	call send_data_to_ay
	djnz l3d61
	ld a,#07
	ld c,#b8
	call send_data_to_ay
	ret

.l3d72
	ld hl,l3f79
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (l3ee4),de
	ld (l3eea),hl

	ld hl,l3f85
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (l3ee6),de
	ld (l3eec),hl

	ld hl,l3f91
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (l3ee8),de
	ld (l3eee),hl

	call l3ddd
	call l3e29
	call l3e76
	ret
;
.play_music	; l3da6
;
	ld a,(l3ef0)
	dec a
	ld (l3ef0),a
	push af
	call z,l3ddd
	pop af
	dec a
	ld c,#00
	call z,l3e23
	ld a,(l3ef1)
	dec a
	ld (l3ef1),a
	push af
	call z,l3e29
	pop af
	dec a
	ld c,#00
	call z,l3e70
	ld a,(l3ef2)
	dec a
	ld (l3ef2),a
	push af
	call z,l3e76
	pop af
	ld c,#00
	dec a
	ret nz
	jp l3ec7

.l3ddd
	ld hl,(l3ee4)
.l3de0
	ld b,(hl)
	inc hl
	ld c,(hl)
	inc hl
	ld a,b
	cp #ff
	jr nz,l3e00

	ld hl,(l3eea)
	inc hl
	ld a,(hl)
	dec hl
	cp #ff
	jr nz,l3df6

	ld hl,l3f79
.l3df6
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (l3eea),hl
	ex de,hl
	jr l3de0

.l3e00
	ld (l3ee4),hl

	ld a,c
	ld (l3ef0),a
	ld a,b

	cp #01
	ld c,#00
	jp z,l3e23

	ld c,b
	ld b,#00
	ld hl,l3eed
	add hl,bc
	xor a
	ld c,(hl)
	inc hl
	call send_data_to_ay
	inc a
	ld c,(hl)
	call send_data_to_ay
	ld c,#0a
.l3e23
	ld a,#08
	call send_data_to_ay
	ret
.l3e29
	ld hl,(l3ee6)
.l3e2c
	ld b,(hl)
	inc hl
	ld c,(hl)
	inc hl
	ld a,b
	cp #ff
	jr nz,l3e4c
	ld hl,(l3eec)
	inc hl
	ld a,(hl)
	dec hl
	cp #ff
	jr nz,l3e42
	ld hl,l3f85
.l3e42
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (l3eec),hl
	ex de,hl
	jr l3e2c

.l3e4c
	ld (l3ee6),hl
	ld a,c
	ld (l3ef1),a
	ld a,b
	cp #01
	ld c,#00
	jp z,l3e70
	ld c,b
	ld b,#00
	ld hl,l3eed
	add hl,bc
	ld a,#02
	ld c,(hl)
	inc hl
	call send_data_to_ay
	inc a
	ld c,(hl)
	call send_data_to_ay
	ld c,#0a
	.l3e70
	ld a,#09
	call send_data_to_ay
	ret
.l3e76
	ld hl,(l3ee8)
.l3e79
	ld b,(hl)
	inc hl
	ld c,(hl)
	inc hl
	ld a,b
	cp #ff
	jr nz,l3e99
	ld hl,(l3eee)
	inc hl
	ld a,(hl)
	dec hl
	cp #ff
	jr nz,l3e8f
	ld hl,l3f91
.l3e8f
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (l3eee),hl
	ex de,hl
	jr l3e79

.l3e99
	ld (l3ee8),hl
	ld a,c
	ld (l3ef2),a
	ld a,b
	or a
	jr z,l3ecd
	cp #01
	ld c,#00
	jp z,l3ec7
	ld c,b
	ld b,#00
	ld hl,l3f05
	add hl,bc
	ld a,#04
	ld c,(hl)
	inc hl
	call send_data_to_ay
	inc a
	ld c,(hl)
	call send_data_to_ay
	ld c,#b8
.l3ec0
	ld a,#07
	call send_data_to_ay
	ld c,#0b
.l3ec7
	ld a,#0a
	call send_data_to_ay
	ret

.l3ecd
	ld a,#06
	ld c,#1e
	call send_data_to_ay
	ld c,#00
	ld a,#04
	call send_data_to_ay
	inc a
	call send_data_to_ay
	ld c,#99
	jp l3ec0

.l3ee4
	defw &0000
.l3ee6
	defw &0000
.l3ee8
	defw &0000
.l3eea
	defw &0000
.l3eec
	db #00
.l3eed
	db #00
.l3eee
	db #00,#00
.l3ef0
	db #00
.l3ef1
	db #00
.l3ef2
	db #00

	dw #06a7,#0647,#05ed,#0598
	dw #0547,#04fc,#04b4,#0470
.l3f05	equ $ +2
	dw #0431,#03f4,#03bc,#0386
	dw #0353,#0324,#02f6,#02cc
	dw #02a4,#027e,#025a,#0238
	dw #0218,#01fa,#01de,#01c3
	dw #01aa,#0192,#017b,#0166
	dw #0152,#013f,#012d,#011c
	dw #010c,#00fd,#00ef,#00e1
	dw #00d5,#00c9,#00be,#00b3
	dw #00a9,#009f,#0096,#008e
	dw #0086,#007f,#0077,#0071
	dw #006a,#0064,#005f,#0059
	dw #0054,#0050,#004b,#0047
	dw #0043,#003f,#003c,#0038
	dw #0035,#0032,#002f,#002d
	dw #002a,#0028,#0026

.l3f79
	defw l3fa9,l3fe0,l3ff9,l3ff9
	defw l405a,&ffff
.l3f85
	defw l4073,l40aa,l40c3,l40c3
	defw l4124,&ffff
.l3f91
	defw l413d,l41fe,l422f,l428f
	defw l428f,l428f,l422f,l428f
	defw l428f,l428f,l42a8,&ffff

.l3fa9
	db #74,#1e,#70,#0a,#70,#28,#6a,#1e
	db #66,#0a,#66,#28,#5c,#1e,#62,#0a
	db #62,#14,#5c,#14,#60,#1e,#78,#0a
	db #78,#14,#70,#14,#74,#1e,#70,#0a
	db #70,#28,#6c,#1e,#6a,#0a,#6a,#14
	db #6a,#14,#5c,#1e,#5c,#0a,#60,#0a
	db #60,#14,#62,#0a,#62,#50,#ff
.l3fe0
	db #58,#1e,#54,#0a,#54,#28,#5c,#1e
	db #58,#0a,#58,#28,#56,#1e,#52,#0a
	db #52,#28,#4e,#1e,#52,#0a,#52,#28
	db #ff
.l3ff9
	db #64,#1e,#52,#0a,#56,#0a,#5a,#0a
	db #5c,#0a,#60,#05,#64,#05,#66,#1e
	db #52,#0a,#56,#0a,#5a,#0a,#5c,#0a
	db #60,#05,#64,#05,#6a,#0a,#6a,#14
	db #6a,#0a,#74,#0a,#66,#0a,#6a,#0a
	db #6e,#0a,#6e,#1e,#74,#0a,#72,#0a
	db #6e,#0a,#6c,#0a,#6a,#0a,#6a,#1e
	db #74,#0a,#74,#0a,#72,#0a,#6e,#0a
	db #66,#0a,#66,#1e,#72,#0a,#72,#0a
	db #6e,#0a,#66,#0a,#64,#0a,#64,#1e
	db #6e,#0a,#6e,#0a,#6a,#0a,#64,#14
	db #60,#1e,#64,#0a,#64,#14,#66,#14
	db #ff
.l405a
	db #52,#1e,#4e,#0a,#4e,#28,#56,#1e
	db #52,#0a,#52,#28,#58,#1e,#54,#0a
	db #54,#28,#5c,#1e,#58,#0a,#58,#28
	db #ff
.l4073
	db #6c,#1e,#6a,#0a,#6a,#28,#62,#1e
	db #60,#0a,#60,#28,#56,#1e,#5c,#0a
	db #5c,#14,#56,#14,#58,#1e,#66,#0a
	db #66,#14,#60,#14,#6c,#1e,#6a,#0a
	db #6a,#28,#64,#1e,#64,#0a,#64,#14
	db #64,#14,#56,#1e,#56,#0a,#54,#0a
	db #54,#14,#52,#0a,#52,#50,#ff
.l40aa
	db #54,#1e,#4e,#0a,#4e,#28,#58,#1e
	db #52,#0a,#52,#28,#52,#1e,#4c,#0a
	db #4c,#28,#48,#1e,#4c,#0a,#4c,#28
	db #ff
.l40c3
	db #5c,#1e,#4c,#0a,#4e,#0a,#52,#0a
	db #56,#0a,#5a,#05,#5c,#05,#60,#1e
	db #4c,#0a,#4e,#0a,#52,#0a,#56,#0a
	db #5a,#05,#5c,#05,#64,#0a,#64,#14
	db #64,#0a,#6e,#0a,#60,#0a,#64,#0a
	db #66,#0a,#66,#1e,#6e,#0a,#6a,#0a
	db #66,#0a,#66,#0a,#64,#0a,#64,#1e
	db #6e,#0a,#6e,#0a,#6a,#0a,#66,#0a
	db #60,#0a,#60,#1e,#6a,#0a,#6a,#0a
	db #66,#0a,#60,#0a,#5c,#0a,#5c,#1e
	db #66,#0a,#66,#0a,#64,#0a,#5c,#14
	db #5a,#1e,#5c,#0a,#5c,#14,#66,#14
	db #ff
.l4124
	db #4e,#1e,#48,#0a,#48,#28,#52,#1e
	db #4c,#0a,#4c,#28,#54,#1e,#4e,#0a
	db #4e,#28,#54,#1e,#52,#0a,#52,#28
	db #ff
.l413d
	db #32,#0a,#4a,#05,#4a,#05,#00,#0a
	db #4a,#05,#4a,#05,#32,#0a,#4a,#05
	db #4a,#05,#00,#0a,#4a,#05,#4a,#05
	db #28,#0a,#40,#05,#40,#05,#00,#0a
	db #40,#05,#40,#05,#28,#0a,#40,#05
	db #40,#05,#00,#0a,#40,#05,#40,#05
	db #36,#0a,#4e,#05,#4e,#05,#00,#0a
	db #4e,#05,#4e,#05,#36,#0a,#4e,#05
	db #4e,#05,#00,#0a,#4e,#05,#4e,#05
	db #28,#0a,#40,#05,#40,#05,#00,#0a
	db #40,#05,#40,#05,#28,#0a,#40,#05
	db #40,#05,#00,#0a,#40,#05,#40,#05
	db #32,#0a,#4a,#05,#4a,#05,#00,#0a
	db #4a,#05,#4a,#05,#32,#0a,#4a,#05
	db #4a,#05,#00,#0a,#4a,#05,#4a,#05
	db #2c,#0a,#44,#05,#44,#05,#00,#0a
	db #44,#05,#44,#05,#2c,#0a,#44,#05
	db #44,#05,#00,#0a,#44,#05,#44,#05
	db #36,#0a,#4e,#05,#4e,#05,#00,#0a
	db #4e,#05,#4e,#05,#28,#0a,#40,#05
	db #40,#05,#00,#0a,#40,#05,#40,#05
	db #32,#0a,#4a,#05,#4a,#05,#00,#0a
	db #4a,#05,#4a,#05,#32,#0a,#4a,#05
	db #4a,#05,#00,#0a,#4a,#05,#4a,#05
	db #ff
.l41fe
	db #01,#0a,#28,#0a,#00,#14,#01,#0a
	db #28,#0a,#00,#14,#01,#0a,#28,#0a
	db #00,#14,#01,#0a,#28,#0a,#00,#14
	db #01,#0a,#3a,#0a,#00,#14,#01,#0a
	db #3a,#0a,#00,#14,#01,#0a,#3a,#0a
	db #00,#14,#01,#0a,#3a,#0a,#00,#14
	db #ff
.l422f
	db #2c,#0a,#44,#05,#44,#05,#00,#0a
	db #44,#05,#44,#05,#2c,#0a,#44,#05
	db #44,#05,#00,#0a,#44,#05,#44,#05
	db #3a,#0a,#52,#05,#52,#05,#00,#0a
	db #52,#05,#52,#05,#3a,#0a,#52,#05
	db #52,#05,#00,#0a,#52,#05,#52,#05
	db #2c,#0a,#44,#05,#44,#05,#00,#0a
	db #44,#05,#44,#05,#2c,#0a,#44,#05
	db #44,#05,#00,#0a,#44,#05,#44,#05
	db #36,#0a,#4e,#05,#4e,#05,#00,#0a
	db #4e,#05,#4e,#05,#36,#0a,#4e,#05
	db #4e,#05,#00,#0a,#4e,#05,#4e,#05
.l428f
	db #3a,#0a,#52,#05,#52,#05,#00,#0a
	db #52,#05,#52,#05,#3a,#0a,#52,#05
	db #52,#05,#00,#0a,#52,#05,#52,#05
	db #ff
.l42a8
	db #01,#0a,#3a,#0a,#00,#14,#01,#0a
	db #3a,#0a,#00,#14,#01,#0a,#3a,#0a
	db #00,#14,#01,#0a,#3a,#0a,#00,#14
	db #01,#0a,#28,#0a,#00,#14,#01,#0a
	db #28,#0a,#00,#14,#01,#0a,#28,#0a
	db #00,#14,#01,#0a,#28,#0a,#00,#14
	db #ff

.game_name
	db "One Man & His Droid",0
.game_year
	db "1985",0
.game_publisher
	db "Mastertronic",0
.music_author
	db "Clive Brooker & Ed Hickman",0
.music_comment
	db "",0
	
	read "music_end_v1_0.asm"
